package group.hhsw.purchase.utils;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;

public class CalculateDate {

    //根据购买时间和产品周期计算产品截止日期
    public static LocalDate calculate(Integer months, LocalDate now) {
        Instant date = now.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant();
        Date date1 = Date.from(date);
        Calendar instance = Calendar.getInstance();
        instance.setTime(date1);
        instance.add(Calendar.MONTH, months);
        return instance.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

}
